<?php

/**
 * Sede filter form base class.
 *
 * @package    BCWeb
 * @subpackage filter
 * @author     Jhonny Fuentes
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseSedeFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'name'             => new sfWidgetFormFilterInput(),
      'description'      => new sfWidgetFormFilterInput(),
      'telefono'         => new sfWidgetFormFilterInput(),
      'latitud'          => new sfWidgetFormFilterInput(),
      'longitud'         => new sfWidgetFormFilterInput(),
      'direccion'        => new sfWidgetFormFilterInput(),
      'pais_id'          => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Pais'), 'add_empty' => true)),
      'provincia_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Provincia'), 'add_empty' => true)),
      'partido_id'       => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Partido'), 'add_empty' => true)),
      'localidad_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Localidad'), 'add_empty' => true)),
      'barrio_id'        => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Barrio'), 'add_empty' => true)),
      'institucion_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Institucion')),
    ));

    $this->setValidators(array(
      'name'             => new sfValidatorPass(array('required' => false)),
      'description'      => new sfValidatorPass(array('required' => false)),
      'telefono'         => new sfValidatorPass(array('required' => false)),
      'latitud'          => new sfValidatorPass(array('required' => false)),
      'longitud'         => new sfValidatorPass(array('required' => false)),
      'direccion'        => new sfValidatorPass(array('required' => false)),
      'pais_id'          => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Pais'), 'column' => 'id')),
      'provincia_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Provincia'), 'column' => 'id')),
      'partido_id'       => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Partido'), 'column' => 'id')),
      'localidad_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Localidad'), 'column' => 'id')),
      'barrio_id'        => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Barrio'), 'column' => 'id')),
      'institucion_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Institucion', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('sede_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addInstitucionListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.SedeInstitucion SedeInstitucion')
      ->andWhereIn('SedeInstitucion.institucion_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Sede';
  }

  public function getFields()
  {
    return array(
      'id'               => 'Number',
      'name'             => 'Text',
      'description'      => 'Text',
      'telefono'         => 'Text',
      'latitud'          => 'Text',
      'longitud'         => 'Text',
      'direccion'        => 'Text',
      'pais_id'          => 'ForeignKey',
      'provincia_id'     => 'ForeignKey',
      'partido_id'       => 'ForeignKey',
      'localidad_id'     => 'ForeignKey',
      'barrio_id'        => 'ForeignKey',
      'institucion_list' => 'ManyKey',
    );
  }
}
